//
//  AppDelegate.m
//  L7_test
//
//  Created by Mac on 11-12-28.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "AppDelegate.h"
#import "FMDBManager.h"
#import "FMDatabase.h"
#import "MobClick.h"
#import "Constants.h"
@implementation AppDelegate

@synthesize window;
@synthesize rootController;
@synthesize shopListController;
@synthesize status;
@synthesize recieveDictionary;
@synthesize supId;
- (void)dealloc
{
    
    
    
    

    
    recieveDictionary=nil;

}

-(void)setRecieveDictionary:(NSMutableDictionary *)dictionary{
    recieveDictionary = [[ NSMutableDictionary alloc] initWithDictionary:dictionary copyItems:YES];
}

//应用程序启动后直接进行应用程序级编码的主要方式
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

   
    
    //启动友盟日志
    [MobClick setLogEnabled:NO];
    [MobClick startWithAppkey:@"50b9c10452701528990000ef" reportPolicy:REALTIME channelId:@"tongbu"];
    [MobClick updateOnlineConfig];
    [MobClick checkUpdate];
    

    if(self.window.bounds.size.height==568){
        NSLog(@"iphone5");
        SSiphoneType=1;
        SSsupplierCount=7;
        SSsupplierCountForUrl=@"pageSize=7";
        SStopViewHeight=167+IOS5HEIGHT;
        SScouponConImg=368+IOS5HEIGHT;
        SScouponConAdd=361+IOS5HEIGHT;
        SSsupplierListH=325+IOS5HEIGHT;
        SScouponScrollview=370+IOS5HEIGHT;
        SScollectionImg=12;
        SScollectionCount=24;
    }else{
        NSLog(@"iphone4");
        SSiphoneType=0;
        SSsupplierCount=5;
        SSsupplierCountForUrl=@"pageSize=5";
        SStopViewHeight=167;
        SScouponConImg=368;
        SScouponConAdd=361;
        SSsupplierListH=325;
        SScouponScrollview=370;
        SScollectionImg=9;
        SScollectionCount=18;
    }
    
   [self.window addSubview:rootController.view];
   
    //如何有新的活动，显示new
//    UIViewController *tController = [rootController.viewControllers objectAtIndex:3];
//    tController.tabBarItem.badgeValue = @"new";
    
    
   [self.window makeKeyAndVisible];
   return YES;
}

//当应用程序将要入非活动状态执行，在此期间，应用程序不接收消息或事件，比如来电话了
- (void)applicationWillResignActive:(UIApplication *)application
{
    
//    NSLog(@"applicationWillResignActive,进入非活动状态");
    //可以让下载，音频播放等都能在后台播放
//        [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


//当程序被推送到后台的时候调用。所以要设置后台继续运行，则在这个函数里面设置即可
- (void)applicationDidEnterBackground:(UIApplication *)application
{
//    NSLog(@"applicationDidEnterBackground，进入后台");
    //可以让下载，音频播放等都能在后台播放
//    [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
//    NSLog(@"%@",NSStringFromSelector(_cmd));
//    
//    //得到当前应用程序的UIApplication对象
//    UIApplication *app = [UIApplication sharedApplication];
//    
//    //一个后台任务标识符
//    UIBackgroundTaskIdentifier taskID;
//    taskID = [app beginBackgroundTaskWithExpirationHandler:^{
//        //如果系统觉得我们还是运行了太久，将执行这个程序块，并停止运行应用程序
//        [app endBackgroundTask:taskID];
//    }];
//    //UIBackgroundTaskInvalid表示系统没有为我们提供额外的时候
//    if (taskID == UIBackgroundTaskInvalid) {
//        NSLog(@"Failed to start background task!");
//        return;
//    }
//    NSLog(@"Starting background task with %f seconds remaining", app.backgroundTimeRemaining);
//    [NSThread sleepForTimeInterval:10];
//    NSLog(@"Finishing background task with %f seconds remaining",app.backgroundTimeRemaining);
//    //告诉系统我们完成了
//    [app endBackgroundTask:taskID];
    
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
     If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
     */
}


//当程序从后台将要重新回到前台时候调用
- (void)applicationWillEnterForeground:(UIApplication *)application
{
//    NSLog(@"applicationWillEnterForeground，进入前台");
    /*
     Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
     */
}

//当应用程序入活动状态执行
- (void)applicationDidBecomeActive:(UIApplication *)application
{
//    NSLog(@"applicationDidBecomeActive，进入活动状态");
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
//    NSLog(@"applicationWillTerminate");
    /*
     Called when the application is about to terminate.
     Save data if appropriate.
     See also applicationDidEnterBackground:.
     */
    FMDBManager *fmdbManager= [[FMDBManager alloc]init];
    FMDatabase *db=[fmdbManager getDataBase]; 
    [db close];
}


//-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{  
//    //  [self.view addSubview:viewController.view];  
//    //  tabBarController.selectedViewController = viewController;  
//    rootController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",80];  
//    //  viewController.tabBarItem.title = @"aaa";  
//} 
//setSelectedIndex


@end



//兼容ios4.0和5.0的自定义导航背景颜色
@implementation UINavigationBar (Extension)

- (UIImage *)barBackground
{
    return [UIImage imageNamed:@"searchBarBg-d.png"];
}
- (void)didMoveToSuperview
{
    //iOS5 only
    if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
    {
        [self setBackgroundImage:[self barBackground] forBarMetrics:UIBarMetricsDefault];
        
    }

}

//this doesn't work on iOS5 but is needed for iOS4 and earlier
- (void)drawRect:(CGRect)rect
{
    //draw image
    [[self barBackground] drawInRect:rect];
}
@end
